

/*
 * @Author: cuijin(Jean Cui) 
 * @Date: 2018-01-26 10:09:11 
 * @Last Modified by: cuijin(Jean Cui)
 * @Last Modified time: 2018-01-26 23:00:39
 */

 

 var webpack = require('webpack');
 //使css文件独立打包 不会打包到js中去
 var ExtractTextPlugin   = require('extract-text-webpack-plugin');

 var HtmlWebpackPlugin   = require('html-webpack-plugin');

 var WEBPACK_ENV = process.env.WEBPACK_ENV || 'dev'

 var getHTMLPlugins = function(name, title) {
    return {
        template: './src/view/' + name + '.html',
        filename: 'view/' + name + '.html',
        title: title,
        inject: true,
        hash: true,
        chunks: ['common', name]
    }
 }

 var config = {
    entry: {
        index: ['./src/page/index/index.js'],
        login: ['./src/page/login/index.js'],
        common: ['./src/page/common/index.js']
    },
    output: {
        path: __dirname + '/dist/',
        publicPath: 'dev' === WEBPACK_ENV ? '/dist/' : '',
        filename: 'js/[name].js'
    },
    resolve : {
        alias : {
            node_modules    : __dirname + '/node_modules',
            util            : __dirname + '/src/util',
            page            : __dirname + '/src/page',
            service         : __dirname + '/src/service',
            image           : __dirname + '/src/image'
        }
    },
    module: {
        rules: [
            {
                test: /\.css$/, 
                loader: ExtractTextPlugin.extract({
                    use: 'css-loader',
                    fallback: 'style-loader'
                })
            },
            { 
                test: /\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/, 
                loader: 'url-loader?limit=100&name=resource/[name].[ext]' 
            }
        ]
    },
    externals : {
        'jquery' : 'window.jQuery'
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            name: 'common',
            filename: 'js/base.js'
        }),
        new ExtractTextPlugin("css/[name].css"),
        
        new HtmlWebpackPlugin(getHTMLPlugins('index', '首页')),
        new HtmlWebpackPlugin(getHTMLPlugins('login', '登录'))

    ]

 }
 
 if('dev' === WEBPACK_ENV){
    config.entry.common.push('webpack-dev-server/client?http://localhost:8088/');
    console.log("cccccccccccc")
}

 module.exports = config;